﻿using System;
using System.Collections.Generic;
using System.Text;

namespace System.IO
{
    class Delete
    {
        class Program
        {
            static void Main(string[] args)
            {
                //在D盘下创建code文件夹
                Directory.CreateDirectory("D:\\code");
                Directory.CreateDirectory("D:\\code-1");
                string path = "D:\\code\\test1.txt";
                //创建文件
                FileStream fs = File.Create(path);
                //获取文件信息
                Console.WriteLine("文件创建时间：" + File.GetCreationTime(path));
                Console.WriteLine("文件最后被写入时间：" + File.GetLastWriteTime(path));
                //关闭文件流
                fs.Close();
                //设置目标路径
                string newPath = "D:\\code-1\\test1.txt";
                //判断目标文件是否存在
                bool flag = File.Exists(newPath);
                if (flag)
                {
                    //删除文件
                    File.Delete(newPath);
                }
                File.Move(path, newPath);
            }
        }
    }
}
